package com.prp.gwt.client.widgets;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class ConfirmDialog extends DialogBox{

	private static ConfirmDialog instance;
	private IWidget widget;
	private Object arg;
	
	public static ConfirmDialog getInstance(){
		if(instance == null)
			instance = new ConfirmDialog();
		return instance;
	}
	
	public void setCallFunction(IWidget widget, Object arg){
		this.widget = widget;
		this.arg = arg;
	}
	
	public void show(String title, String message){
		clear();
		setText(title);
		VerticalPanel vPanel = new VerticalPanel();
		vPanel.add(new HTML(message));
		HorizontalPanel hPanel = new HorizontalPanel();
		Button confirmButton = new Button("确认");
		Button cancelButton = new Button("取消");
		hPanel.add(confirmButton);
		hPanel.add(cancelButton);
		vPanel.add(hPanel);
		vPanel.setSpacing(10);
		hPanel.setSpacing(10);
		add(vPanel);
		confirmButton.addClickHandler(new ClickHandler(){
			@Override
			public void onClick(ClickEvent event) {
				widget.callFunction(arg);
				hide();
			}
		});
		cancelButton.addClickHandler(new ClickHandler(){
			@Override
			public void onClick(ClickEvent event) {
				hide();
			}
		});
		center();
	}
	
}
